// export const apiBase="http://localhost:8888"
// export const websocketBase="ws://localhost:8888/ws"

export const apiBase="http://10.8.8.22:32765"
export const websocketBase="ws://10.8.8.22:32765/ws"


export async function checkNickName(roomName,nickname){
    const url=`${apiBase}/nickname/check/${roomName}/${nickname}`
    const data = await request(url)
    return data.hasSameName

}

export async function getPersonInRoom(roomName) {
    const url = `${apiBase}/all/persons/${roomName}`
    const data = await request(url)
    return data.persons
}

async function request(url) {
    const response = await fetch(url);
    if(!response.ok){
        throw new Error("网络请求异常")
    }
    const data =await response.json()
    if (!data.success) {
        throw new Error("api请求错误")
    }
    return data
}
